package com.xiaotao.controller;

import com.xiaotao.dto.GroupBuyDto;
import com.xiaotao.service.GroupBuyService;
import com.xiaotao.util.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "团购相关")
@RestController
@RequestMapping("groupBuy")
public class GroupBuyController {
    @Resource
    private GroupBuyService groupBuyService;

    @ApiOperation(value = "查询全部团购信息")
    @GetMapping("{pageNum}/{pageSize}")
    public ResponseUtil findAll(@PathVariable Integer pageNum,@PathVariable Integer pageSize){
        return groupBuyService.findAll(pageNum,pageSize);
    }

    @ApiOperation(value = "查询指定商户的团购信息")
    @GetMapping("{merchantId}")
    public ResponseUtil findByMerchantId(@PathVariable Integer merchantId){
        return groupBuyService.findByMerchantId(merchantId);
    }

    @ApiOperation(value = "添加团购信息")
    @PostMapping
    public ResponseUtil save(@RequestBody GroupBuyDto groupBuyDto){
        return groupBuyService.save(groupBuyDto);
    }

    @ApiOperation(value = "删除团购信息")
    @DeleteMapping("{id}")
    public ResponseUtil delete(@PathVariable Integer id){
        return groupBuyService.delete(id);
    }

    @ApiOperation(value = "修改团购信息")
    @PutMapping()
    public ResponseUtil update(@RequestBody GroupBuyDto groupBuyDto){
        return groupBuyService.update(groupBuyDto);
    }

    @ApiOperation(value = "根据团购id查询团购信息")
    @PostMapping("{id}")
    public ResponseUtil findById(@PathVariable Integer id){
        return groupBuyService.findById(id);
    }
}
